package myky.com.doctorapp.model

import com.xiangyao.train.utils.RxScedulerHelper
import io.reactivex.Observable
import myky.com.doctorapp.api.ApiManager
import myky.com.doctorapp.base.BaseEntity
import myky.com.doctorapp.contract.DoctorListContract
import myky.com.doctorapp.entity.DepatmentAndAreaEntity
import myky.com.doctorapp.entity.DoctorWrapperEntity
import myky.com.doctorapp.utils.RequestBodyBuilder

class DoctorListModel : DoctorListContract.Model {
    override fun findDeparmentAndArea(version: String): Observable<BaseEntity<DepatmentAndAreaEntity.DataEntity>> {
        val requestBodyBuilder = RequestBodyBuilder.Builder()

        val requestBody = requestBodyBuilder.params("version", version)

                .build()

        return ApiManager.getApistore().findDeapatmentAndArea(requestBody).compose(RxScedulerHelper.io_main())


    }

    override fun findDoctorList(version: String, customerId: String, size: Int,
                                current: Int, type: String, searchScope: Int,
                                input: String, province: String, city: String,
                                departmentname: String): Observable<BaseEntity<DoctorWrapperEntity.DoctorListEntity>> {

        val requestBodyBuilder = RequestBodyBuilder.Builder()

        requestBodyBuilder.params("version", version)
                .params("customerId", customerId)
                .params("size", size.toString())
                .params("current", current.toString())
                .params("type", type)
                .params("searchScope", searchScope.toString())
                .params("input", input)
        if (province != "全部地区") {
            requestBodyBuilder.params("province", province)
        }
        if (city != "全部地区") {
            requestBodyBuilder.params("city", city)
        }
        if (departmentname != "全部科室") {
            requestBodyBuilder.params("departmentname", departmentname)
        }
        val requestBody = requestBodyBuilder.build()


        return ApiManager.getApistore().findDoctorList(requestBody).compose(RxScedulerHelper.io_main())
    }
}
